package com.funny.rabbitmq.deadqueue;

import com.funny.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Consumer2 {
    private final static String DEAD_QUEUE_NAME = "dead.queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();

        // 声明交换机
        channel.basicConsume(DEAD_QUEUE_NAME, true, (consumerTag, message) -> {
            String msg = new String(message.getBody());
            log.info("consumerTag={}, message={}", consumerTag, msg);
            long deliveryTag = message.getEnvelope().getDeliveryTag();
            String routingKey = message.getEnvelope().getRoutingKey();
            log.info("deliveryTag={}, routingKey={}", deliveryTag, routingKey);
        }, consumerTag -> {
            log.info("consumerTag={}", consumerTag);
        });

    }

    private static boolean handleMsg(String msg) {
        String[] strs = msg.split("_");
        int n = Integer.parseInt(strs[1]);
        return n > 2;
    }
}
